package com.yufan.mq.kafka;


import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * spring boot demo
 * 生产者
 */
@RestController
public class BootKafkaProducer {

    /*
        <dependency>
			<groupId>org.springframework.kafka</groupId>
			<artifactId>spring-kafka</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.kafka</groupId>
			<artifactId>spring-kafka-test</artifactId>
			<scope>test</scope>
		</dependency>
    */

    private KafkaTemplate<String, String> kafkaTemplate;

    public BootKafkaProducer(KafkaTemplate<String, String> kafkaTemplate) {
        this.kafkaTemplate = kafkaTemplate;
    }


    @GetMapping("/kafka/send")
    public String send() {
        String topicName = "java-demo-topic";
        kafkaTemplate.send(topicName, 0, "key", "this is a msg");
        return null;
    }

}
